package com.celan.year2023.month01.day13;

public class Solution {
    /**
     * leetcode2287
     */
    public int rearrangeCharacters(String s, String target) {
        int[] dic = new int[26];
        for (int i = 0; i < s.length(); i++) {
            dic[s.charAt(i) - 'a']++;
        }
        int cnt = 0;
        boolean flag = true;
        while (flag) {
            for (int i = 0; i < target.length(); i++) {
                char c = target.charAt(i);
                if (dic[c - 'a'] == 0) {
                    flag = false;
                    break;
                }
                dic[c - 'a']--;
            }
            if (flag) cnt++;
        }
        return cnt;
    }
}
